package com.lyrcsoft.application;

import com.lyrcsoft.application.config.AppConfig;
import com.lyrcsoft.beanfactorypostprocessor.MyBeanDefinitionRegistryPostProcessor;
import com.lyrcsoft.listener.MyApplicationEvent;
import com.lyrcsoft.listener.MyApplicationListener2;
import com.lyrcsoft.service.T6Service;
import com.lyrcsoft.service.T8Service;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author fujc-dev@qq.com
 * @date 2023/6/30 9:54
 */

public class Programs {

	public static void main(String[] args) {
		MyAnnotationConfigApplicationContext context = new MyAnnotationConfigApplicationContext();
		context.register(AppConfig.class);
		//context.addApplicationListener(new MyApplicationListener2());
		// 设置环境变量必须有指定的Key
		//context.getEnvironment().setRequiredProperties("customs");
		//context.addBeanFactoryPostProcessor(new MyBeanDefinitionRegistryPostProcessor());
		//context.getBeanFactory().registerSingleton("myBeanDefinitionRegistryPostProcessor", new MyBeanDefinitionRegistryPostProcessor());
		//AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		//beanDefinition.setBeanClass(MyBeanDefinitionRegistryPostProcessor.class);
		//context.registerBeanDefinition("myBeanDefinitionRegistryPostProcessor",beanDefinition);
		context.refresh();
		// 销毁
		// context.close();

		// 注册进程关闭的钩子，触发Bean销毁
		context.registerShutdownHook();
		//AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		//LookupTestService lookupTestService = context.getBean(LookupTestService.class);
		//lookupTestService.test();
		//lookupTestService.test();
		//lookupTestService.test();
		// spring.components 好像不支持LookUp注解
		//UserService userService = context.getBean("userService", UserService.class);
		//userService.test();

		//OrderService orderService = context.getBean("orderService1", OrderService.class);
		//orderService.test();

		//SmartInitializingSingletonService singletonService = context.getBean(SmartInitializingSingletonService.class);
		//singletonService.test();

		//ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
		//System.out.println(context.getBean("userService"));
		//System.out.println(context.getBean("userService"));
		//System.out.println(context.getBean("userService"));

		//MyFactoryBean my = context.getBean("&myFactoryBean",MyFactoryBean.class);
		//System.out.println(my);

		//T1Service t1Service = context.getBean(T1Service.class);
		//t1Service.test();

		//T4Service t4Service = context.getBean(T4Service.class);
		//t4Service.test();

		//T5Service t5Service = context.getBean(T5Service.class);
		//t5Service.test();

		//context.getBeanDefinition("t6Service").getPropertyValues().add("t7Service", new T7Service());

		//T6Service t6Service = context.getBean(T6Service.class);
		//t6Service.test();

		//T8Service t8Service = context.getBean(T8Service.class);
		//t8Service.test();

		//context.publishEvent(new MyApplicationEvent("user"));
	}
}
